package com.usc.uscface.controller;

import com.usc.uscface.enums.ActionRecognition;
import com.usc.uscface.enums.ActionRecognitions;
import com.usc.uscface.tools.Face;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author HadwinLing
 * @version V1.0
 * @Package com.usc.uscface.controller
 * @date 2020/12/3 20:02
 */
@Controller
public class ActionRecognitionController {

    Face face = new Face("http://127.0.0.1","5000");

    @Value("${vector_target}")
    private String vector_target;
    @Value("${picture_target}")
    private String picture_target;
    @Value("${tempPath}")
    private String tempPath;
    @Value("${activePath}")
    private String activePath;



    @PostMapping("/action_recognition")
    @ResponseBody
    public ActionRecognition actionRecognition(MultipartFile file2 ) throws IOException {
        String action_Recognition_path = "";
        ActionRecognition actionRecognition = face.actionRecognition(file2, action_Recognition_path);
        return actionRecognition;
    }


    @PostMapping("/action_recognitions")
    @ResponseBody
    public ActionRecognitions actionRecognitions(HttpServletRequest request, HttpServletResponse response) throws IOException {
        MultipartHttpServletRequest params=((MultipartHttpServletRequest) request);
        List<MultipartFile> files = params.getFiles("file5");//file为文件项的name值
        String banjiName = "";
        for (int j = 0; j < files.size(); j++) {
            banjiName = face.uploadFile(files.get(j), activePath);
        }
        activePath = activePath+"\\"+banjiName;
        ActionRecognitions actionRecognitions = face.actionRecognitions(activePath);
        System.out.println("actionRecognitions:"+actionRecognitions);

        return actionRecognitions;
    }



}
